package com.mijie.homi.dao.commom;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.mijie.core.IBatisDao;
import com.mijie.homi.domain.commom.Review;

@Repository
public class ReviewDao extends IBatisDao {

	public Review getReview(Review.Module module,int id){
		HashMap<String,Object> parameter = new HashMap<String,Object>(3);
		parameter.put("tableName", Review.getReviewTable(module));
		parameter.put("id",id);
		return this.selectOne("getReview", parameter);
	}
	
	public int newReview(Review.Module module,Review review){
		review.setCreateAt(new Date());
		review.setTableName(Review.getReviewTable(module));
		return this.insert("newReview", review);
	}
	
	/**
	 * @param eventId 以后分表使用
	 */
	public int deleteReview(Review.Module module,long eventId,int id,Integer reviewer){
		HashMap<String,Object> parameter = new HashMap<String,Object>(3);
		parameter.put("tableName", Review.getReviewTable(module));
		parameter.put("id",id);
		if(reviewer!=null)
			parameter.put("reviewer", reviewer);
		return this.delete("deleteReview",parameter);
	}
	
	public List<Review> listReview(Review.Module module,long eventId,int offset,int limit){
		HashMap<String,Object> parameter = new HashMap<String,Object>(4);
		parameter.put("tableName", Review.getReviewTable(module));
		parameter.put("eventId",eventId);
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return this.selectList("listReview", parameter);
	}
}
